<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/user_php.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	$con = @mysql_connect('localhost', 'root', '');
	if (!$con) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}
	
	mysql_set_charset('utf8');
	$db_selected = @mysql_select_db('studial');
	if (!$db_selected) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}

	$sql="SELECT * FROM friends WHERE (user_id='".$_COOKIE['studialuserid']."' AND friend_id='".$_GET['id']."') OR (friend_id='".$_COOKIE['studialuserid']."' AND user_id='".$_GET['id']."');";
	$result = mysql_query($sql);
	$rows = mysql_num_rows($result);
	$i = 2; //themselves
	if($rows)
	{
		//friend
		$i = 1;
	}
	else if ($_COOKIE['studialuserid'] != $_GET['id'])
	{
		//not friend
		$i = 0;
	}
	
	//Get homeboard info
	$sql="SELECT * FROM `users` WHERE `id`='".$_GET['id']."'";
	$result=mysql_query($sql);
	$row=mysql_fetch_array($result);
	$fullnametarget=$row["lastname"]." ".$row["firstname"];
	
	//Get homeboard info
	$sql="SELECT * FROM `users` WHERE `id`='".$_COOKIE['studialuserid']."'";
	$result=mysql_query($sql);
	$row=mysql_fetch_array($result);
	$fullnameuser=$row["lastname"]." ".$row["firstname"];
?>
<title><?php echo $fullnametarget; ?></title>
<link rel="stylesheet" type="text/css" href="../css/global.css" />
<link rel="stylesheet" type="text/css" href="../css/loggedpages.css" />
<!-- InstanceBeginEditable name="head" -->
<link rel="stylesheet" type="text/css" href="../css/forms.css" />
<script type="text/javascript" language="javascript" src="../javascript/forms.js"></script>
<style type="text/css">
	#centercontainer {
		margin: 3em auto 1em auto;
		width: 560px;
	}
	
	#editform {
		padding: 1.5em 6.5em 5em 5.3em;
		display: block;
		background-color: #ededed;
		color: #666666;
		font-size: 13px;
		border-top: 1pt solid #d0d0d0;
	}
	
	.leftlabel { font-weight: 600; }
	
	.textinput { font-size: 13px; }
</style>
<!-- InstanceEndEditable -->
</head>

<body>  
    <div class="header">
        <div class="innercontent">
            <img alt="Studial" class="logo" src="../images/logo.jpg" />   
            <form id="searchform" method="post" action="">
                <div id="searchblock">
                    <input id="searchfield" name="searchfield" type="text" placeholder="Tìm kiếm" />
                    <button id="searchbutton" type="submit" name="search" value="1" title="Tìm kiếm" onclick="window.location = '../unlogged/index.php'"><img id="searchicon" src="../images/searchicon.png" /></button>
                </div>           
            </form>
            <div id="rightheader">
                <a class="headerbutton" id="logout" href="../unlogged/logout.php"><span id="borderleft"></span>Đăng xuất</a>
                <a class="headerbutton" id="toboard" href="<?php echo "../users/addfriend.php?id=".$_COOKIE["studialuserid"]; ?>"><?php echo $fullnameuser; ?></a>
            </div>
        </div>
    </div>
    <div class="innercontent">
        <div id="leftcolumn">
            <img alt="Avatar" id="largeavatar" src="<?php echo $path = "../images/male_avatar.png"; ?>" />
        	<div id="sidenavcontainer">	
                <ul id="sidenav">
            		<li><a class="navlink" href="homeboard.php?id=<?php echo $_GET['id']; ?>"><span id="boardnav">Bảng</span></a></li>
                    <li><a class="navlink" href="infoview.php?id=<?php echo $_GET['id']; ?>"><span id="infonav">Thông tin</span></a></li>
                    <li><a class="navlink" href="friendlist.php?id=<?php echo $_GET['id']; ?>"><span id="friendnav">Bạn bè</span></a></li>
                    <li><a class="navlink" href="phovidallview.php?id=<?php echo $_GET['id']; ?>"><span id="phovidnav">Phim ảnh</span></a></li>
                    <li><a class="navlink" href="courselist.php?id=<?php echo $_GET['id']; ?>"><span id="coursenav">Khóa học</span></a></li>
            	</ul>
            </div>
        </div>
        <div id="contentcolumn">
        	<div id="contentcolheader">
            	<h2><?php echo $fullnametarget; ?></h2>
                <?php 
					if ($i == 0) { 
						echo "<a id=\"addfriend\" href=\"../users/addfriend.php?id=".$_GET["id"]."\"><button class=\"greenbutton\">Kết bạn</button></a>";
					}
				 	else if ($i == 1) {
						echo "<a id=\"removefriend\" href=\"../users/removefriend.php?id=".$_GET["id"]."\"><button class=\"greenbutton\">Chia tay</button></a>"; 
					}
				?>  
            </div>
		<!-- InstanceBeginEditable name="maincontent" -->
        <?php
			function getuserinfo($id)
			{
				$result = mysql_query("select * from `users` where `id` = '".$id."';");
				$rows = mysql_fetch_array($result);
				return $rows;	
			}
			function edituser($id)
			{
				$lastname = $_POST['lastname'];
				$firstname = $_POST['firstname'];
				$gender = $_POST['gender'];
				$day = $_POST['day'];
				$month = $_POST['month'];
				$year = $_POST['year'];
				$dob = $year."-".$month."-".$day;
				
				$result = mysql_query("update `users` set `lastname` = '".$lastname."', `firstname` = '".$firstname."', `gender` = '".$gender."', `birthday` = '".$dob."' where `id` = '".$id."';");				
			}
			
			//------------------------------------------------
			$user_id = $_COOKIE['studialuserid'];
			
			if(isset($_POST['lastname']))
			{
				edituser($user_id);
			}
						
			$userinfo = getuserinfo($user_id);			
			
		?>
        	<div id="centercontainer">	
                <form id="editform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $user_id; ?>">        
                    <label class="leftlabel" for="lastname">Họ:</label>
                    <input class="textinput" name="lastname" type="text" value="<?php echo $userinfo["lastname"]; ?>" /> 
                    <label class="leftlabel" for="firstname">Tên:</label>
                    <input class="textinput" name="firstname" type="text" value="<?php echo $userinfo["firstname"]; ?>" /> 
                    <label class="leftlabel" for="gender">Bạn là:</label>
                    <select class="dropinput" name="gender" id="gender">
                        <option value="0" <?php if ($userinfo['gender']==0) echo "selected=\"selected\"0"; ?>>Nữ</option>
                        <option value="1" <?php if ($userinfo['gender']==1) echo "selected=\"selected\"1"; ?>>Nam</option>
                    </select><br />
                    <label class="leftlabel">Ngày sinh:</label>
                    <select class="dropinput" name="day" id="day" onfocus="setDays();">
                        <option value="0" selected="selected">Ngày:</option>
                    </select>
                    <select class="dropinput" name="month" id="month" onfocus="setMonths();" onchange="setDays();">
                        <option value="0" selected="selected">Tháng:</option>
                    </select>
                    <select class="dropinput" name="year" id="year" onfocus="setYears();" onchange="setDays(); setMonths();">
                        <option value="0" selected="selected">Năm:</option>
                    </select>
                    <button class="greenbutton" name="submit" value="1" onclick="showLoader();">Sửa</button>
                    <img alt="Loading..." class="loader" id="loader" src="../Images/loader01.gif" />
                </form>
            </div>
		<!-- InstanceEndEditable -->
    	</div>
    </div>
    <div class="footer">
    	<div id="leftfooter">Studial @ 2012 - Nhóm 01</div>
        <div id="rightfooter">
			<a href="" title="Đăng ký thêm tên trường vào hệ thống">Đăng ký trường</a>
            -
            <a href="" title="Đăng ký thêm tên ngành học vào hệ thống">Đăng ký ngành</a>
        </div>
    </div>       
</body>
<!-- InstanceEnd --></html>
